Hello, Column ColRef = currentColumn() int ColWidth = width(ColRef)
DBE LayoutCanvas = getCanvas() int RowHeight = height(LayoutCanvas)
bool getCalculatingLayoutHeight_() // I want this! // int getCalculatedLayoutHeight_()
SystemAdmin - Thu Feb 16 06:50:09 EST 2012 |
Re: getCalculatedLayoutHeight Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS |
Re: getCalculatedLayoutHeight Mathias Mamsch - Thu Feb 16 08:00:42 EST 2012 Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS We have some Text Attributes with way too many paragraphs in them, or tall embedded oles. I was after a way of identifying the height in order to look at splitting them into additional objects. Can't really do it by paragraph count due to oles. Guess I could calculate from oleDimensions, but wondered if there was just a simple 'ObjectHeight' function I had missed. Adam |
Re: getCalculatedLayoutHeight Am newbie at canvases, but I wanted to draw a pretty label on my dialog and wanted a routine to predice how Wide and High it needed to me. Below is the code. I see that I'm getting benign exception violations, at times, no matter how I adjust the 'sleep_' parameter. Maybe someone can improve it; or more likely scrap it and show the easy way.
// These ratios are I guess for default 'Helvetica' font. Will need to check on that
real c_DbeCanvas_RatioWidth = 1.2,
c_DbeCanvas_RatioHeight = 1.5,
c_DbeCanvas_RatioPosition = 0.75
// Timing problems requires a 'sleep_(x)'after the 'realize' command
int c_DbeCanvas_Sleep_Standard = 40, // Milliseconds to sleep, standard -
c_DbeCanvas_Sleep_Recover = 150 // Recovery time to sleep when error detected
int g_DbeCanvas_CountFail1 = 0,
g_DbeCanvas_CountFail2 = 0
bool DbeCanvas_Debug_AckOneErrMess = false // true (for debugging) means display one such "font" error to the user,
// false (for deployment) means don't display the error.
//*************************************************
bool fl_DbeCanvas_GetSize(string in_Text, int in_Sleep, int in_Level, int in_Mode, int &out_Width, &out_Height, &out_Position)
{ // Internal function for user function fDbeCanvas_GetSize.
// Try to determine the size, return if there was an error
// Parameters the same, except:
// After 'realize', sleep_ for in_Sleep milliseconds
// When there is an error, the "&out_" parameters are not touched
void clbkTemp(DBE dbeXX){} // Dummy callback for 'canvas' command following
DB dbTemp = create("XX")
DBE dbeCan = canvas(dbTemp, 400, 50, clbkTemp)
string ErrMess = ""
bool OK
realize(dbTemp, 7000, 7000)
sleep_(in_Sleep)
noError()
font(dbeCan, in_Level, in_Mode)
ErrMess = lastError()
if (!null ErrMess)
{ OK = false
if (DbeCanvas_Debug_AckOneErrMess)
{ DbeCanvas_Debug_AckOneErrMess = false // Prevent display any more such errors
print "\t>>fl_DbeCanvas_GetSize, ErrMess = " ErrMess
}
}
else
{ OK = true
out_Width = intOf(realOf(width (dbeCan, in_Text))*c_DbeCanvas_RatioWidth)
out_Height = intOf(realOf(height(dbeCan, in_Text))*c_DbeCanvas_RatioHeight)
out_Position = intOf(realOf(height(dbeCan, in_Text))*c_DbeCanvas_RatioPosition)
// print ErrMess
}
hide(dbTemp)
destroy(dbTemp)
return(OK)
//print "Width/Height = [" in_Text "]\n" out_Width "\t" out_Height "\t" out_Position "\n"
} // end fl_DbeCanvas_GetSize()
//*************************************************
void fDbeCanvas_GetSize(string in_Text, int in_Level, int in_Mode, int &out_Width, &out_Height, &out_Position)
{ // Determine the Width and Height needed to create a canvas that will display the Text only,
// for the specified display Level and Mode.
// The in_Level and in_Mode are those the caller will use in the subsequent 'font' command
// The out_Width and out_Height are those the caller should use in the subsequent DBE = canvas(..) command
// The int_Text and out_Position are those the caller should use in the subsequent 'draw' command.
// Developer's note: v9.3.0.4 seemed to introduce a wierd timing issue within fl_DbeCanvas_GetSize above,
// where we could not deal with the canvas even after it was realized, because it seemed
// that sometimes the dialog wasn't actually yet shown when the canvas "font" command was issued.
// So I determined that introducing a "sleep_" command before "font" almost always resolved the issue.
// So this code now issues a "sleep_" for a small amount of time (c_DbeCanvas_Sleep_Standard), and if that
// fails it tries again with a longer time (c_DbeCanvas_Sleep_Recover), which always works.
// Thus, we only sleep a long time if the short time fails, and testing shows the short time succeeds
// over one time in a thousand.
if (! fl_DbeCanvas_GetSize(in_Text, c_DbeCanvas_Sleep_Standard, in_Level, in_Mode, out_Width, out_Height, out_Position))
{ g_DbeCanvas_CountFail1++
if (!fl_DbeCanvas_GetSize(in_Text, c_DbeCanvas_Sleep_Recover, in_Level, in_Mode, out_Width, out_Height, out_Position))
{ // FAILURE.
// Attempt to guess reasonable sizes:
// This is probably a function of the current display font and size but
// I don't want to do all that tricky work
g_DbeCanvas_CountFail2++
out_Width = intOf(realOf(length(in_Text))*8.0*c_DbeCanvas_RatioWidth)
out_Height = intOf(22.0*c_DbeCanvas_RatioHeight)
out_Position = intOf(22.0*c_DbeCanvas_RatioPosition)
}
}
} // end fDbeCanvas_GetSize()
// Here's a sample use
fx_DbeCanvas_GetSize(c_Canvas_Intrfce_Text, c_Canvas_Level, c_Canvas_Font,
g_Canvas_Intrfce_Width, g_Canvas_Intrfce_Height, g_Canvas_Intrfce_Position)
dbeCnsl_cnvsIntrfce = canvas(dbConsole, g_Canvas_Intrfce_Width, g_Canvas_Intrfce_Height, Canvas_clbkDraw)
dbeCnsl_cnvsIntrfce ->"right" ->"unattached"
|
Re: getCalculatedLayoutHeight llandale - Thu Feb 16 14:20:20 EST 2012 Am newbie at canvases, but I wanted to draw a pretty label on my dialog and wanted a routine to predice how Wide and High it needed to me. Below is the code. I see that I'm getting benign exception violations, at times, no matter how I adjust the 'sleep_' parameter. Maybe someone can improve it; or more likely scrap it and show the easy way.
// These ratios are I guess for default 'Helvetica' font. Will need to check on that
real c_DbeCanvas_RatioWidth = 1.2,
c_DbeCanvas_RatioHeight = 1.5,
c_DbeCanvas_RatioPosition = 0.75
// Timing problems requires a 'sleep_(x)'after the 'realize' command
int c_DbeCanvas_Sleep_Standard = 40, // Milliseconds to sleep, standard -
c_DbeCanvas_Sleep_Recover = 150 // Recovery time to sleep when error detected
int g_DbeCanvas_CountFail1 = 0,
g_DbeCanvas_CountFail2 = 0
bool DbeCanvas_Debug_AckOneErrMess = false // true (for debugging) means display one such "font" error to the user,
// false (for deployment) means don't display the error.
//*************************************************
bool fl_DbeCanvas_GetSize(string in_Text, int in_Sleep, int in_Level, int in_Mode, int &out_Width, &out_Height, &out_Position)
{ // Internal function for user function fDbeCanvas_GetSize.
// Try to determine the size, return if there was an error
// Parameters the same, except:
// After 'realize', sleep_ for in_Sleep milliseconds
// When there is an error, the "&out_" parameters are not touched
void clbkTemp(DBE dbeXX){} // Dummy callback for 'canvas' command following
DB dbTemp = create("XX")
DBE dbeCan = canvas(dbTemp, 400, 50, clbkTemp)
string ErrMess = ""
bool OK
realize(dbTemp, 7000, 7000)
sleep_(in_Sleep)
noError()
font(dbeCan, in_Level, in_Mode)
ErrMess = lastError()
if (!null ErrMess)
{ OK = false
if (DbeCanvas_Debug_AckOneErrMess)
{ DbeCanvas_Debug_AckOneErrMess = false // Prevent display any more such errors
print "\t>>fl_DbeCanvas_GetSize, ErrMess = " ErrMess
}
}
else
{ OK = true
out_Width = intOf(realOf(width (dbeCan, in_Text))*c_DbeCanvas_RatioWidth)
out_Height = intOf(realOf(height(dbeCan, in_Text))*c_DbeCanvas_RatioHeight)
out_Position = intOf(realOf(height(dbeCan, in_Text))*c_DbeCanvas_RatioPosition)
// print ErrMess
}
hide(dbTemp)
destroy(dbTemp)
return(OK)
//print "Width/Height = [" in_Text "]\n" out_Width "\t" out_Height "\t" out_Position "\n"
} // end fl_DbeCanvas_GetSize()
//*************************************************
void fDbeCanvas_GetSize(string in_Text, int in_Level, int in_Mode, int &out_Width, &out_Height, &out_Position)
{ // Determine the Width and Height needed to create a canvas that will display the Text only,
// for the specified display Level and Mode.
// The in_Level and in_Mode are those the caller will use in the subsequent 'font' command
// The out_Width and out_Height are those the caller should use in the subsequent DBE = canvas(..) command
// The int_Text and out_Position are those the caller should use in the subsequent 'draw' command.
// Developer's note: v9.3.0.4 seemed to introduce a wierd timing issue within fl_DbeCanvas_GetSize above,
// where we could not deal with the canvas even after it was realized, because it seemed
// that sometimes the dialog wasn't actually yet shown when the canvas "font" command was issued.
// So I determined that introducing a "sleep_" command before "font" almost always resolved the issue.
// So this code now issues a "sleep_" for a small amount of time (c_DbeCanvas_Sleep_Standard), and if that
// fails it tries again with a longer time (c_DbeCanvas_Sleep_Recover), which always works.
// Thus, we only sleep a long time if the short time fails, and testing shows the short time succeeds
// over one time in a thousand.
if (! fl_DbeCanvas_GetSize(in_Text, c_DbeCanvas_Sleep_Standard, in_Level, in_Mode, out_Width, out_Height, out_Position))
{ g_DbeCanvas_CountFail1++
if (!fl_DbeCanvas_GetSize(in_Text, c_DbeCanvas_Sleep_Recover, in_Level, in_Mode, out_Width, out_Height, out_Position))
{ // FAILURE.
// Attempt to guess reasonable sizes:
// This is probably a function of the current display font and size but
// I don't want to do all that tricky work
g_DbeCanvas_CountFail2++
out_Width = intOf(realOf(length(in_Text))*8.0*c_DbeCanvas_RatioWidth)
out_Height = intOf(22.0*c_DbeCanvas_RatioHeight)
out_Position = intOf(22.0*c_DbeCanvas_RatioPosition)
}
}
} // end fDbeCanvas_GetSize()
// Here's a sample use
fx_DbeCanvas_GetSize(c_Canvas_Intrfce_Text, c_Canvas_Level, c_Canvas_Font,
g_Canvas_Intrfce_Width, g_Canvas_Intrfce_Height, g_Canvas_Intrfce_Position)
dbeCnsl_cnvsIntrfce = canvas(dbConsole, g_Canvas_Intrfce_Width, g_Canvas_Intrfce_Height, Canvas_clbkDraw)
dbeCnsl_cnvsIntrfce ->"right" ->"unattached"
Another, more general situation in which I would like to determine the height, is in order to draw an icon taking the full size of the column - as the Object is currently displayed. This changes depending on text wrapping due to column widths. This is so people can still see the icon when the top of the object is scrolled off the top of the screen. Eg. Colour the Full Cloumn Red/Green to represent some bool attribute. If you simply set the background colour of the canvas, only the equivalent height of 1 Line is coloured. |